package net.logax.games.chase;

import javax.microedition.khronos.opengles.GL10;

import net.logax.games.framework.gl.Vertices3;
import net.logax.games.framework.math.Vector3;

public class ModelSolidPlotter {
	GL10 gl;

	public ModelSolidPlotter(GL10 gl) {
		this.gl = gl;
	}

	public void plot(RenderableGameObject gameObject) {
		float x = gameObject.position.x;
		float y = gameObject.position.y;
		float z = gameObject.position.z;
		plot(gameObject, x, y, z);
	}

	public void plotToPosition(RenderableGameObject gameObject, Vector3 position) {
		float x = position.x;
		float y = position.y;
		float z = position.z;
		plot(gameObject, x, y, z);
	}

	private void plot(RenderableGameObject gameObject, float x, float y, float z) {
		Vertices3 model = gameObject.getModel();
		model.bind();
		gl.glPushMatrix();
		gl.glTranslatef(x, y, z);
		int primitiveType = GL10.GL_TRIANGLES;
		model.draw(primitiveType, 0, model.getNumVertices());
		gl.glPopMatrix();
		model.unbind();
	}

	public void plotToPositionRotateCCWOnY(RenderableGameObject gameObject,
			Vector3 position, float angle) {
		Vertices3 model = gameObject.getModel();
		model.bind();
		gl.glPushMatrix();
		float x = position.x;
		float y = position.y;
		float z = position.z;
		gl.glTranslatef(x, y, z);
		gl.glRotatef(angle, 0, 1, 0);
		int primitiveType = GL10.GL_TRIANGLES;
		model.draw(primitiveType, 0, model.getNumVertices());
		gl.glPopMatrix();
		model.unbind();
	}
}
